package magicloan.auctionpocket.ui.fragment;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.chad.library.adapter.base.BaseQuickAdapter;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;

import magicloan.auctionpocket.R;
import magicloan.auctionpocket.adapter.ThirdFgLeftRecylerAdapter;
import magicloan.auctionpocket.adapter.ThirdFgRightRecylerAdapter;
import magicloan.auctionpocket.bean.ProduceBean;
import magicloan.auctionpocket.ui.base.BaseFragment;

/**
 * Created by hechao on 2018/1/25.
 */
public class ThirdFragment extends BaseFragment {

    private ThirdFgRightRecylerAdapter mRightAdapter ;
    private ThirdFgLeftRecylerAdapter mLeftAdapter ;
    private ArrayList<ProduceBean> mReDateList ;

    @Override
    protected int setFgContentView() {
        return R.layout.fg_third;
    }

    @Override
    protected void initView() {

    }

    @Override
    protected void beforeInitView() {
        mReDateList = new ArrayList<>() ;
        for ( int i = 0 ; i < 10 ; i ++ ){
            ProduceBean instance = new ProduceBean();
            mReDateList.add(instance);
        }
        initAdapter();
    }


    @Override
    protected void afterInitView() {

        RecyclerView re_right = (RecyclerView) mContentView.findViewById(R.id.re_right);
        LinearLayoutManager layoutManager_right = new LinearLayoutManager(mContext);
        re_right.setLayoutManager(layoutManager_right);
        re_right.setAdapter(mRightAdapter);
        mRightAdapter.addData(mReDateList);
        mRightAdapter.notifyDataSetChanged();


        RecyclerView re_left = (RecyclerView) mContentView.findViewById(R.id.re_left);
        LinearLayoutManager layoutManager_left = new LinearLayoutManager(mContext);
        re_left.setLayoutManager(layoutManager_left);
        re_left.setAdapter(mLeftAdapter);
        mLeftAdapter.addData(mReDateList);
        mLeftAdapter.notifyDataSetChanged();

        mViewEmpty = mContentView.findViewById(R.id.view_empty);
        mViewEmpty.setVisibility(View.INVISIBLE);

    }

    private void initAdapter() {

        mRightAdapter = new ThirdFgRightRecylerAdapter(R.layout.fg_third_re_right_item, mActivity);
        mRightAdapter.setOnLoadMoreListener(new MyRequestLoadMoreListener());
        mRightAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);

        mLeftAdapter = new ThirdFgLeftRecylerAdapter(R.layout.fg_third_re_left_item, mActivity);
        mLeftAdapter.setOnLoadMoreListener(new MyRequestLoadMoreListener());
        mLeftAdapter.openLoadAnimation(BaseQuickAdapter.ALPHAIN);

    }

    private class MyRequestLoadMoreListener implements BaseQuickAdapter.RequestLoadMoreListener {

        @Override
        public void onLoadMoreRequested() {
//            if (!isLoadMore) {
//                isLoadMore = true;
//                currentPage = ++currentPage;
//                mService.getRefreshLoanData(NetConstance.GetLoanData, currentPage, 6);
//            }
        }

    }

    @Override
    protected void initData() {

    }

    @Override
    public void onClick(View v) {

    }

    @Override
    public void afterConnectSuccess(String flag, JSONObject request) throws JSONException {

    }

    @Override
    public void afterConnectFail(String flag, JSONObject result, String cache) throws JSONException {

    }

}
